package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 合同成本-运维项目
 * @TableName t_contract_project
 */
@TableName(value ="t_contract_project")
@Data
public class TContractProject implements Serializable {
    /**
     * ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    
    /**
     * 合同流水号
     */
    @TableField(value = "contract_id")
    private Integer contractId;
  
  /**
   * 行项目号
   */
  @TableField(value = "line_no")
  private String lineNo;
  
  @ApiModelProperty("项目编号")
  private String projectCode;
  /**
   * WBS项目编号
   */
  @TableField(value = "project_id")
  private Integer projectId;
  
  public TContractProject(Integer projectId, String projectCode, Integer contractId) {
    this.contractId = contractId;
    this.lineNo = "";
    this.projectId = projectId;
    this.projectCode = projectCode;
  }
    
    public static List<TContractProject> toList(List<TContractWbsProject> wbsProjects, Integer contractId) {
        List<TContractProject> contractProjectList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(wbsProjects)) {
            wbsProjects.stream().forEach(wbsProject -> {
                TContractProject project = new TContractProject(wbsProject.getProjectId(), wbsProject.getProjectCode(), contractId);
              contractProjectList.add(project);
            });
        }
        return contractProjectList;
    }
}